//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __GENDEV_H__
#define __GENDEV_H__

//#define _DBGGENDEV

#define CLS_Storage     110
#define CLS_Display     120
#define CLS_Touch       130
#define CLS_Keypad      140
#define CLS_Timer       150
#define CLS_Serial      160
#define CLS_Audio       170
#define CLS_Camera      180
#define CLS_Battery     190

#define CLS2INX(cls)     (cls/10-10)

class CGenDev : public CDeviceDriver
{
public:
    CGenDev();

    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    // It's Maybe have no use for the keyboard driver.
    virtual void Dispose() {}

    IDeviceDriver * DevStub[10];

    inline IDeviceDriver *GetDriver(int DevCls)
    {
        int i = CLS2INX(DevCls);
#if defined(_DBGGENDEV)
        printf("Index %d\n", i);
#endif
        if (i < 0 || i >= 10)
			return NULL;
        return DevStub[i];
    }
};

#endif//__GENDEV_H__
